/**
 * Copyright (c) 2008,中企动力华南研发中心
 * All rights reserved.
 */

package com.ce.pms.charge.web;

import java.util.List;

import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.charge.service.INoteService;
import com.ce.pms.charge.service.IPeriodService;
import com.ce.pms.charge.vo.NoteVO;
import com.ce.pms.charge.vo.PeriodVO;
import com.ce.pms.house.service.IBuildingService;
import com.ce.pms.house.vo.BuildingVO;
import com.sitechasia.webx.components.xtable.util.ExtremeUtils;
import com.sitechasia.webx.core.annotation.Out;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.support.Page;

/**
 * 逻辑、功能相关描述:
 * @author 许海堆  编写日期：2008-9-12
 */

public class NoteAction extends PmsBaseAction{

	private IBuildingService buildingService = null;  //楼栋
	private IPeriodService periodService = null;  //收费周期
	private INoteService noteService = null;  //通知单
	/**
	 * 功能描述:  初始化主页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-12  <br>
	 */
	public String initMain(){
		initCache();//缓存楼栋,周期下拉列表
		return "main";
	}

	/**
	 * 功能描述:  初始化通知单列表页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-12  <br>
	 */
	public String initList(){
		setAttribute("totalRows", Integer.valueOf(0));
		return "list";
	}

	/**
	 * 功能描述:  初始化催缴列表页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-12  <br>
	 */
	public String initReminderList(){
		setAttribute("totalRows", Integer.valueOf(0));
		return "reminderList";
	}

	/**
	 * 功能描述:  初始化重新生成页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-17  <br>
	 */
	public String initBuildAnew(){
		PeriodVO temp = periodService.queryCurrentPeriod();
		setAttribute("periodVO", temp);
		return "buildAnew";
	}

	/**
	 * 功能描述:  查看通知单详细信息<br>
	 * @param noteId
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-18  <br>
	 */
	public String initNoteDetail(@Read(key="noteId")Long noteId){
		NoteVO noteVO = noteService.findNoteById(noteId);
		setAttribute("noteVO", noteVO);
		return "noteDetail";
	}

	/**
	 * 功能描述:<br>
	 * @param noteId
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-18  <br>
	 */
	public String listTransRNote(@Read NoteVO noteVO,
								 @Read(key="ec_p", defaultValue="1") int pageNo,
								 @Read(key="ec_crd",defaultValue="10")int pageSize) {
		noteVO.setPageNo(pageNo);
		noteVO.setPageSize(pageSize);

		Page page = noteService.findTransRNoteByNoteId(noteVO);

		setAttribute("totalRows", Integer.valueOf(String.valueOf(page.getTotalCount())));
		setAttribute("transRNote", page.getResult());
		return "transRNoteList";
	}
	/**
	 * 功能描述: 根据查询条件查询通知单列表 <br>
	 * @param noteVO
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-9-16  <br>
	 */
	public String list(@Read NoteVO noteVO,
				 	   @Read(key="ec_p", defaultValue="1") int pageNo,
					   @Read(key="ec_crd",defaultValue="15")int pageSize){
		//设置排序字段  分页大小,框架处理后 .noteVO 不会为空
		String orderStr = ExtremeUtils.getOrderString(getRequest());
		noteVO.setSortStr(orderStr);
		noteVO.setPageNo(pageNo);
		noteVO.setPageSize(pageSize);
		//到后台查询列表
		Page page=noteService.queryNote(noteVO);
		List noteList =page.getResult();
		//缓存列表数据
		setAttribute("noteList", noteList);
		setAttribute("totalRows", new Integer((int) page.getTotalCount()));
		return "list";
	}

	/**
	 * 功能描述:根据查询条件查询通知单列表(主线界面)<br>
	 * @param <br>
	 * @return<br>
	 *
	 * Create author:xuhaidui<br>
	 * Create on:2009-1-21<br>
	 * Edit author:<br>
	 * Edit on:<br>
	 * Why:<br>
	 */
	public String houseMainLinelist(@Read @Out(key="noteVO") NoteVO noteVO,
		 	   @Read(key="ec_p", defaultValue="1") int pageNo,
			   @Read(key="ec_crd",defaultValue="10")int pageSize){

	list(noteVO,pageNo,pageSize);

	List<PeriodVO> periodList = periodService.findPeriodByValidity(null);
	setAttribute("periodList", periodList);
	setAttribute("HouseIds", noteVO.getHouseIds());
	return "houseMainLineNoteList";
	}



	/**
	 * 功能描述:  生成通知单<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-9-16  <br>
	 */
	public void buildNotes(){
		Boolean flag = noteService.buildNote(this.getUserId());
		renderText(String.valueOf(flag));
	}

	/**
	 * 功能描述:  选择房屋范围，重新生成<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-9-17  <br>
	 */
	public void buildNotesAnew(@Read(key="houseIds")String houseIds){
		Boolean flag = noteService.reBuildNote(getUserId(),houseIds);
		renderText(flag.toString());
	}
	/**
	 * 功能描述:  重新生成通知单，针对个房间<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-9-18  <br>
	 */
	public void buildNotesAnewForOne(@Read(key="houseId")String houseId){
		Boolean flag = noteService.reBuildNote(super.getUserId(), houseId);
		renderText(flag.toString());
	}
    /**
	 * 功能描述:房间重新生成通知单
	 * @param refreshIframe 页面保存之后调用哪个iframe里面的refresh()来刷新页面
	 * @return
	 * Create author:xuhaidui
	 * Create on:2008-8-21
	 */
	public String reCreateNoteForOneHouse(@Read(key="keyword")Long keyword,@Read(key="periodId")Long periodId,
			@Read(key="refreshIframe",defaultValue="main")@Out(key="refreshIframe")String refreshIframe){
		return "onlyRefresh";
	}

	/**
	 * 功能描述: 根据查询条件查询 催缴单 列表  <br>
	 * @param noteVO
	 * @param pageNo
	 * @param pageSize
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-5  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String reminderList(@Read NoteVO noteVO,
				 	   @Read(key="ec_p", defaultValue="1") int pageNo,
					   @Read(key="ec_crd",defaultValue="15")int pageSize){
		//设置排序字段  分页大小,框架处理后 .noteVO 不会为空
		String orderStr = ExtremeUtils.getOrderString(getRequest());
		noteVO.setSortStr(orderStr);
		noteVO.setPageNo(pageNo);
		noteVO.setPageSize(pageSize);
		noteVO.setReminder("1");
		//到后台查询列表
		Page page=noteService.queryNote(noteVO);
		List noteList =page.getResult();
		//缓存列表数据
		setAttribute("noteList", noteList);
		setAttribute("totalRows", new Integer((int) page.getTotalCount()));
		return "reminderList";
	}

	/**
	 * 功能描述: 根据查询条件查询 房间催缴单 列表  <br>
	 * @param noteVO
	 * @param pageNo
	 * @param pageSize
	 * Create author:许海堆 <br>
	 * Create on:2008-11-5  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public String houseMainLinereminderList(@Read @Out(key="noteVO")NoteVO noteVO,
		 	   @Read(key="ec_p", defaultValue="1") int pageNo,
			   @Read(key="ec_crd",defaultValue="10")int pageSize){

		reminderList(noteVO,pageNo,pageSize);

		List<PeriodVO> periodList = periodService.findPeriodByValidity(null);
		setAttribute("periodList", periodList);
		setAttribute("HouseIds", noteVO.getHouseIds());
	return "houseMainLineReminderList";
	}


	/**
	 * 功能描述: 生成催缴单 <br>
	 * Create author:黄彦军 <br>
	 * Create on:2008-11-6  <br>
	 * Edit author:  <br>
	 * Edit on:    <br>
	 * Why:     <br>
	 */
	public void buildReminder(){
		Boolean flag = noteService.buildReminderNote(this.getUserId());
		renderText(String.valueOf(flag));
	}

	/**
	 * 功能描述:  加载主页面时,缓存楼栋列表,收费周期 <br>
	 * Create author:yixianjian <br>
	 * Create on:2008-9-16  <br>
	 */
	private void initCache(){
		//缓存楼栋列表
		List<BuildingVO> buildingList = buildingService.getAllBuildingList();
		setAttribute("buildingList", buildingList);

		///缓存收费周期列表
		List<PeriodVO> periodList = periodService.findPeriodByValidity(null);
		setAttribute("periodList", periodList);
	}

	public void setBuildingService(IBuildingService buildingService) {
		this.buildingService = buildingService;
	}

	public void setPeriodService(IPeriodService periodService) {
		this.periodService = periodService;
	}

	public void setNoteService(INoteService noteService) {
		this.noteService = noteService;
	}
}
